package org.mcflier.appuntamento.main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.mcflier.appuntamento.core.Factory;
import org.mcflier.appuntamento.core.exception.ModulesException;
import org.mcflier.appuntamento.core.logger.LoggerManager;
import org.mcflier.appuntamento.core.modules.ModulesManager;
import org.mcflier.appuntamento.tasks.TaskManager;

public class PeriodicTasks {

	public static void main(String[] args) {
		Factory factory = Factory.getInstance();
		
		try {
			ModulesManager modules = (ModulesManager)factory.getModuleInstance(Factory.MODULE_MODULES);
			TaskManager tasks = (TaskManager)factory.getModuleInstance(Factory.MODULE_TASKS);
			
			modules.loadModules();
			tasks.beginTasks();
			
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String word;
			do{
				System.out.print("Type exit for ending the program: ");
				word = reader.readLine();
				System.out.println();
			}
			while(!word.trim().toLowerCase().equals("exit"));
			System.out.println("Bye!");
			
		} catch (ModulesException e) {
			LoggerManager loggerManager = new LoggerManager();
			loggerManager.getLogger(PeriodicTasks.class.getName()).warning("Error loading modules: "+e.getMessage());
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}